package gunfire.relics;

import basemod.abstracts.CustomRelic;
import com.badlogic.gdx.graphics.Texture;
import com.megacrit.cardcrawl.actions.common.DrawCardAction;
import com.megacrit.cardcrawl.actions.common.GainEnergyAction;
import com.megacrit.cardcrawl.actions.common.RelicAboveCreatureAction;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.relics.AbstractRelic;
import gunfire.GunfireMod;
import gunfire.util.TextureLoader;

import static gunfire.GunfireMod.makeRelicOutlinePath;
import static gunfire.GunfireMod.makeRelicPath;

public class MysticMirror extends CustomRelic {

    public static final String ID = GunfireMod.makeID("MysticMirror");
    private static final Texture IMG = TextureLoader.getTexture(makeRelicPath("MysticMirror.png"));
    private static final Texture OUTLINE = TextureLoader.getTexture(makeRelicOutlinePath("blank.png"));
    private int turn;

    public MysticMirror() {
        super(ID, IMG, OUTLINE, RelicTier.BOSS, LandingSound.CLINK);
        this.turn = 1;
    }

    @Override
    public void atPreBattle() {
        this.turn = 1;
    }

    @Override
    public void atTurnStart() {
        if(this.turn % 2 == 1){
            this.flash();
            this.addToBot(new DrawCardAction(1));
            this.addToTop(new RelicAboveCreatureAction(AbstractDungeon.player, this));
        } else {
            this.flash();
            this.addToBot(new GainEnergyAction(1));
            this.addToTop(new RelicAboveCreatureAction(AbstractDungeon.player, this));
        }
        this.turn++;
    }

    @Override
    public boolean canSpawn() {
        return AbstractDungeon.player.hasRelic("gunfire:StartupFund");
    }

    @Override
    public void obtain() {
        if (AbstractDungeon.player.hasRelic("gunfire:StartupFund")) {
            for(int i = 0; i < AbstractDungeon.player.relics.size(); ++i) {
                if (AbstractDungeon.player.relics.get(i).relicId.equals(StartupFund.ID)) {
                    this.instantObtain(AbstractDungeon.player, i, true);
                    break;
                }
            }
        } else {
            super.obtain();
        }
    }

    @Override
    public String getUpdatedDescription() {
        return DESCRIPTIONS[0];
    }

    @Override
    public AbstractRelic makeCopy() {
        return new MysticMirror();
    }
}
